package com.itheima.Tree;

import java.security.spec.MGF1ParameterSpec;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: Ethan Yankang
 * @Program: code-random-recordings
 * @Date: 2024-08-04 13:17
 **/
class PreOrderTraversal {
    public List<Integer> preorderTraversal(TreeNode root) {
        List resList=new LinkedList<Integer>();
        preOrder(root,resList);
        return resList;
    }

    private void preOrder(TreeNode root,List<Integer> resList) {
        if (root == null) {
            return;
        }
        resList.add(root.val);
        preOrder(root.left,resList);
        preOrder(root.right,resList);
    }
}

